<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>主要内容区main</title>
<link href="../include/css/css.css" type="text/css" rel="stylesheet" />
<link href="../include/css/main.css" type="text/css" rel="stylesheet" />
<link rel="shortcut icon" href="../include/images/main/favicon.ico" />
<style>
body{overflow-x:hidden; background:#f2f0f5; padding:15px 0px 10px 5px;}
#searchmain{ font-size:12px;}
#search{ font-size:12px; background:#548fc9; margin:10px 10px 0 0; display:inline; width:100%; color:#FFF; float:left}
#search form span{height:40px; line-height:40px; padding:0 0px 0 10px; float:left;}
#search form input.text-word{height:24px; line-height:24px; width:180px; margin:8px 0 6px 0; padding:0 0px 0 10px; float:left; border:1px solid #FFF;}
#search form input.text-but{height:24px; line-height:24px; width:55px; background:url(../include/images/main/list_input.jpg) no-repeat left top; border:none; cursor:pointer; font-family:"Microsoft YaHei","Tahoma","Arial",'宋体'; color:#666; float:left; margin:8px 0 0 6px; display:inline;}
#search a.add{ background:url(../include/images/main/add.jpg) no-repeat -3px 7px #548fc9; padding:0 10px 0 26px; height:40px; line-height:40px; font-size:14px; font-weight:bold; color:#FFF; float:right}
#search a:hover.add{ text-decoration:underline; color:#d2e9ff;}
#main-tab{ border:1px solid #eaeaea; background:#FFF; font-size:12px;}
#main-tab th{ font-size:12px; background:url(../include/images/main/list_bg.jpg) repeat-x; height:32px; line-height:32px;}
#main-tab td{ font-size:12px; line-height:40px;}
#main-tab td a{ font-size:12px; color:#548fc9;}
#main-tab td a:hover{color:#565656; text-decoration:underline;}
.bordertop{ border-top:1px solid #ebebeb}
.borderright{ border-right:1px solid #ebebeb}
.borderbottom{ border-bottom:1px solid #ebebeb}
.borderleft{ border-left:1px solid #ebebeb}
.gray{ color:#dbdbdb;}
td.fenye{ padding:10px 0 0 0; text-align:right;}
.bggray{ background:#f9f9f9}
</style>
</head>
<body>
<?php error_reporting(E_ALL & ~E_NOTICE);?>
<!--main_top-->
<table width="99%" border="0" cellspacing="0" cellpadding="0" id="searchmain">
  <tr>
    <td width="99%" align="left" valign="top">您的位置：用户管理&nbsp;&nbsp;>&nbsp;&nbsp;查看类别</td>
  </tr>
  <tr>
    <td align="left" valign="top">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" id="search">
  		<tr>
   		 <td width="90%" align="left" valign="middle">
	         <form action="index.php">
				 <span>名称：</span>
				 <input style="width:100px;" type="text" name="name" value="<?php echo $_GET['name']; ?>" class="text-word">
				 <span>父ID：</span>
				 <input style="width:100px;" type="text" name="pid" value="<?php echo $_GET['pid']; ?>" class="text-word">
				 
				 <select name='pid' style="margin:10px 0px">
                        <option value=''>-请选择-</option>
                        <option value='0' <?php echo $_GET['pid']=='0' ? 'selected' : '';?> >pid</option>
                        <option value='15' <?php echo $_GET['pid']=='15' ? 'selected' : '';?> >path</option>                       
                 </select>

				 <input type="submit" value="查询" class="text-but">
	         </form>
         </td>
  		  <td width="10%" align="center" valign="middle" style="text-align:right; width:150px;"><a href="add.php" target="mainFrame" onFocus="this.blur()" class="add">新增类别</a></td>
  		</tr>
	</table>
    </td>
  </tr>
  <tr>
    <td align="left" valign="top">
    
    <table width="100%" border="0" cellspacing="0" cellpadding="0" id="main-tab">
      <tr>
        <th align="center" valign="middle" class="borderright">ID</th>
        <th align="center" valign="middle" class="borderright" width=280>名称</th>
        <th align="center" valign="middle" class="borderright">父ID</th>
        <th align="center" valign="middle" class="borderright">路径</th>
        <th align="center" valign="middle" width=200>操作</th>
      </tr>
      <?php
		//读取数据
			error_reporting(E_ALL & ~E_NOTICE);
			include('../../public/dbconfig.php');
			$link = mysqli_connect(HOST,USER,PASS,DBNAME);
			mysqli_select_db($link,DBNAME);
			mysqli_set_charset($link,'utf8');
			
		//===========封装搜索条件================
		$wherelist = array();
		$urllsit = array();
		
		if(!empty($_GET['name'])){
			$wherelist[] = "name like '%{$_GET['name']}%'";
			$urllist[] = "name={$_GET['name']}";
		}
		//var_dump($_GET['name']);die;
		//var_dump($_GET['pid']);
		if(!empty($_GET['pid'])||$_GET['pid']=='0'){
			$wherelist[] = "pid={$_GET['pid']}";
			$urllist[] = "pid={$_GET['pid']}";
		}
		
		 //echo '<pre>';
		//print_r($wherelist);die;
		
		if(count($wherelist)>0){
			$where = " where ".implode(" and ",$wherelist);
			$url = "&".implode("&",$urllist);
			//echo $where;die;
		}
		
			//=========分页=============
		$_GET['p'] = empty($_GET['p'])?0:$_GET['p']; //页码
		$pageSize = 8; //每页条数
		$maxPage = 0; //页数
		$maxRow = 0; //总条数
			
			//获得总条数 和总页数
		//2 一共有多少条 
		$sql = "select * from type".$where;
		//echo $sql;die;
		$result = mysqli_query($link,$sql);
		$maxRow = mysqli_num_rows($result);
		//echo $maxRow;
		$maxPage = ceil($maxRow/$pageSize);
		//echo $maxPage;die;
		//判断页码
		//4 判断页码 
		if($_GET['p']>$maxPage){
			$_GET['p'] = $maxPage;
		}
		if($_GET['p']<1){
			$_GET['p']=1;
		}	
		$limit = " limit ".($_GET['p']-1)*$pageSize.",".$pageSize;
			
		
		//echo $sql;die;
		$sql = "select * from type".$where." order by concat(path,id)".$limit;
		//echo $sql;die;
		$result = mysqli_query($link,$sql);
		while($list = mysqli_fetch_assoc($result)){
		
		echo "
		<tr onMouseOut='this.style.backgroundColor=#ffffff' onMouseOver='this.style.backgroundColor=#edf5ff'>
        <td align='center' valign='middle' class='borderright borderbottom'>{$list['id']}</td>
        <td align='center' valign='middle' class='borderright borderbottom'>{$list['name']}</td>
        <td align='center' valign='middle' class='borderright borderbottom'>{$list['pid']}</td>
        <td align='center' valign='middle' class='borderright borderbottom'>{$list['path']}</td>
		<td align='center' valign='middle' class='borderbottom'><a href='edit.php?id={$list['id']}' target='mainFrame' onFocus='this.blur()' class='add'>修改</a><span class='gray'>&nbsp;|&nbsp;</span><a href='action.php?action=del&id={$list['id']}' target='mainFrame' onFocus='this.blur()' class='add'>删除</a><span class='gray'>&nbsp;|&nbsp;</span><a href='add.php?pid={$list['id']}&path={$list[path]}{$list['id']},&type={$list['name']}' target='mainFrame' onFocus='this.blur()' class='add'>添加子类</a></td></tr>";

		}
			
			
	  ?>

    </table></td>
    </tr>
  <tr>
    <td align="left" valign="top" class="fenye"><?php echo $maxRow." 条数据 ".$_GET['p']."/".$maxPage." 页";?>&nbsp;&nbsp;<a href="index.php?p=1<?php echo $url;?>" target="mainFrame" onFocus="this.blur()">首页</a>&nbsp;&nbsp;<a href="index.php?p=<?php echo ($_GET['p']-1).$url;?>" target="mainFrame" onFocus="this.blur()">上一页</a>&nbsp;&nbsp;<a href="index.php?p=<?php echo ($_GET['p']+1).$url;?>" target="mainFrame" onFocus="this.blur()">下一页</a>&nbsp;&nbsp;<a href="index.php?p=<?php echo $maxPage.$url;?>" target="mainFrame" onFocus="this.blur()">尾页</a></td>
  </tr>
</table>
	<?php
		mysqli_free_result($result);
		mysqli_close($link);
		if($_GET['errno']==1){
			echo "<h3 style='color:red;'>商品或类别中存在子类,无法删除</h3>";
		}
	?>
</body>
</html>